import { createRouter, createWebHashHistory, RouteRecordRaw, RouterView } from 'vue-router';
import { NotFound } from '@/components';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';

import AppIndex from '../pages/app-index/app-index';

const routes: Array<RouteRecordRaw> = [
    {
        path: '/user',
        props:{
            hiddInMenu:true,
            hideChildrenInMenu:true
        },
        component: RouterView,
        redirect:'/user/login',
        children: [
            {
                path: '/user/login',
                name: 'login',
                component: () => import('@/pages/app-login/app-login'),
            },
            {
                path: '/user/register',
                name: 'register',
                component: () => import('@/pages/app-register/app-register'),
            },
        ],
    },
    {
        path: '/',
        component: AppIndex,
        children: [
            {
                path: '/',
                redirect: '/user/login',
            },
            {
                path: '/dashboard',
                name: 'dashboard',
                meta: {
                    title: '仪表盘',
                },
                component: RouterView,
                children: [
                    {
                        path: '/dashboard/analysis',
                        meta: {
                            title: '分析页',
                        },
                        name: 'analysis',
                        component: () => import('@/pages/analysis/analysis'),
                    },
                ],
            },
            {
                path: '/configuration',
                name: 'configuration',
                meta: {
                    title: '配置',
                },
                component: RouterView,
                children: [
                    {
                        path: '/configuration/data-source-grid-view',
                        meta: {
                            title: '数据源',
                            caption: '数据源表格视图',
                        },
                        name: 'data-source-grid-view',
                        component: () => import('@/pages/data-source-grid-view/data-source-grid-view'),
                    },
                    {
                        path: '/configuration/run-rule',
                        meta: {
                            title: '运行规则',
                            caption: '运行规则',
                        },
                        name: 'run-rule',
                        component: () => import('@/pages/run-rule-grid-view/run-rule-grid-view'),
                    },
                ],
            },
            {
                path: '/exception',
                name: 'exception',
                meta: {
                    title: '异常页',
                },
                props: {
                    hideChildrenInMenu: true,
                    hideInMenu:true
                },
                component: RouterView,
                children: [
                    {
                        path: '/exception/not-found',
                        meta: {
                            title: '404',
                        },
                        name: 'not-found',
                        component: NotFound,
                    },
                ],
            },
        ],
    },
    {
        path: '/:pathMatch(.*)',
        props: {
            hideInMenu: true,
        },
        name: '404',
        component: NotFound,
    },
];

const router = createRouter({
    history: createWebHashHistory(process.env.BASE_URL),
    routes,
});

router.beforeEach((to, from, next) => {
    NProgress.start();
    next();
});

router.afterEach(() => {
    NProgress.done();
});

export default router;
